package com.yzc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yzc.mapper.UserMapper;
import com.yzc.model.entity.system.SysUser;
import com.yzc.model.vo.system.SysUserVo;
import com.yzc.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class UserServiceImpl extends ServiceImpl<UserMapper, SysUser>
        implements UserService {

    @Autowired
    private UserMapper userBeanMapper;

    public List<SysUserVo> loadaAll() {
        //操作
        return userBeanMapper.loadaAll();
    }

    @Override
    public SysUserVo getUserVoByName(String name) {
        LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysUser::getName, name);
        SysUser sysUser = getOne(queryWrapper);

        if (sysUser == null) {
            return null;
        }

        SysUserVo sysUserVo = new SysUserVo();
        BeanUtils.copyProperties(sysUser, sysUserVo);
        return sysUserVo;
    }

    @Override
    public SysUserVo getInfoById(Long id) {
        SysUser byId = getById(id);
        SysUserVo sysUserVo = new SysUserVo();
        BeanUtils.copyProperties(byId, sysUserVo);
        return sysUserVo;
    }




}




